package org.jeecgframework.web.service.impl;

import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.jeecgframework.web.service.CbsRotaLevelServiceI;
import org.jeecgframework.web.system.pojo.base.CbsRotaLevelEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;
import java.io.Serializable;

@Service("cbsRotaLevelService")
@Transactional
public class CbsRotaLevelServiceImpl extends CommonServiceImpl implements CbsRotaLevelServiceI {


    public <T> void delete(T entity) {
        super.delete(entity);
        //执行删除操作配置的sql增强
        this.doDelSql((CbsRotaLevelEntity) entity);
    }

    public <T> Serializable save(T entity) {
        Serializable t = super.save(entity);
        //执行新增操作配置的sql增强
        this.doAddSql((CbsRotaLevelEntity) entity);
        return t;
    }

    public <T> void saveOrUpdate(T entity) {
        super.saveOrUpdate(entity);
        //执行更新操作配置的sql增强
        this.doUpdateSql((CbsRotaLevelEntity) entity);
    }

    /**
     * 默认按钮-sql增强-新增操作
     *
     * @param id
     * @return
     */
    public boolean doAddSql(CbsRotaLevelEntity t) {
        return true;
    }

    /**
     * 默认按钮-sql增强-更新操作
     *
     * @param id
     * @return
     */
    public boolean doUpdateSql(CbsRotaLevelEntity t) {
        return true;
    }

    /**
     * 默认按钮-sql增强-删除操作
     *
     * @param id
     * @return
     */
    public boolean doDelSql(CbsRotaLevelEntity t) {
        return true;
    }

    /**
     * 替换sql中的变量
     *
     * @param sql
     * @return
     */
    public String replaceVal(String sql, CbsRotaLevelEntity t) {
        sql = sql.replace("#{id}", String.valueOf(t.getId()));
        sql = sql.replace("#{rota_name_chinese}", String.valueOf(t.getRotaNameChinese()));
        sql = sql.replace("#{rota_name}", String.valueOf(t.getRotaName()));
        sql = sql.replace("#{level}", String.valueOf(t.getLevel()));
        sql = sql.replace("#{UUID}", UUID.randomUUID().toString());
        return sql;
    }
}